import numpy as np
# 1 创建整数型数组
arr1 = np.array([1,2,3])
print(type(arr1))
print(arr1)

# 2 创建浮点型数组
arr2 = np.array([1.0,2.1])
print(type(arr2))
print(arr2)

# 整数型数组
arr3 = np.array( [1, 2, 3] )
# 插入浮点数，被截断，数组仍为整数型
arr3[0] = 100.9
print(arr3) # [100   2   3]

# 浮点型数组
arr4 = np.array( [1.0, 2, 3] )
arr4[1] = 10 # 插入整数型，被升级，数组仍为浮点型
print(arr4)  # [ 1. 10.  3.]

# 整数型数组
arr1 = np.array( [1, 2, 3] )
print(arr1) #[1 2 3]

# 整数型数组 ——> 浮点型数组
arr2 = arr1.astype(float)
print(arr1) # [1 2 3]
print(arr2) # [1. 2. 3.]

# 浮点型数组 ——> 整数型数组
arr3 = arr2.astype(int)
print(arr3) # [1 2 3]

arr4 = np.array([1.0,2.2,3.3]).astype(int)
print(arr4) # [1 2 3]

# 整数型数组
arr = np.array( [2, 4, 6] )
print(arr) # [2 4 6]
# 整数型数组与浮点数做运算
print( arr + 0.0 ) # [2. 4. 6.]
print( arr * 1.0 ) # [ 4.  8. 12.]
# 整数型数组遇到除法（即便是除以整数）
print( arr / 1 ) # [2. 4. 6.]
# 整数型数组与浮点型数组做运算
int_arr = np.array( [1, 2, 3] )
float_arr = np.array( [1.0, 2, 3] )
print( int_arr + float_arr ) # [2. 4. 6.]

